<?php
require_once('config.inc.php');

PRINT "<html>";
PRINT "<head><title>Benutzer-Daten editieren</title></head>";
PRINT "<body>";

$dbname = DB_NAME;

if(!@$title = $_POST["title"])
		$title = '';
if(!@$firstname = $_POST["firstname"])
		$firstname = '';
if(!@$lastname = $_POST["lastname"])
		$lastname = '';
if(!@$postcode = $_POST["postcode"])
		$postcode = '';
if(!@$city = $_POST["city"])
		$city = '';
if(!@$country = $_POST["country"])
		$country = '';
if(!@$address = $_POST["address"])
		$address = '';
if(!@$phone = $_POST["phone"])
		$phone = '';
if(!@$position = $_POST["position"])
		$position = '';
if(!@$employer = $_POST["employer"])
		$employer = '';
if(!@$mail = $_POST["mail"])
		$mail = '';
if(!@$homepage = $_POST["homepage"])
		$homepage = '';
$user_id = $_GET["user_id"];

/* make connection to database */
MYSQL_CONNECT(DB_SERVER,DB_USER_NAME,DB_USER_PASSWORD) OR DIE("Datenbankverbindung konnte nicht hergestellt werden!");
@mysql_select_db("$dbname") or die("Datenbank nicht gefunden!"); 

PRINT "Folgende Daten wurden editiert:<br>";
PRINT "<ul>";
PRINT "<li>Titel: <em>$title</em>";
PRINT "<li>Vorname: <em>$firstname</em>";
PRINT "<li>Nachname: <em>$lastname</em>";
PRINT "<li>Adresse: <em>$address</em>";
PRINT "<li>PLZ: <em>$postcode</em>";
PRINT "<li>Ort: <em>$city</em>";
PRINT "<li>Land: <em>$country</em>";
PRINT "<li>Telefon: <em>$phone</em>";
PRINT "<li>E-Mail: <em>$mail</em>";
PRINT "<li>Homepage: <em>$homepage</em>";
PRINT "<li>Arbeitgeber: <em>$employer</em>";
PRINT "<li>Position: <em>$position</em>";
PRINT "</ul>";
PRINT "<hr>";

class EditUserData
{
	function edit($firstname, $lastname, $address, $postcode, $city, $country, $phone, $employer, $mail, $title, $homepage, $position, $user_id)
	{
		/* MySQL table created to store the data */
		$tablename = "userdata";
		
		/* Insert information into table */
		$query = "UPDATE $tablename SET firstname='$firstname', lastname='$lastname', address='$address', postcode=$postcode, city='$city', country='$country', phone='$phone', employer='$employer', mail='$mail', title='$title', homepage='$homepage', position='$position' WHERE user_id='$user_id'";
		$result = MYSQL_QUERY($query);
		
		PRINT "Antwort des Datenbank-Servers:<br>";
		
		if($result)
		{
		  $affected_rows =  mysql_affected_rows();
		  PRINT "<strong>Query OK. Betroffene Zeilen: $affected_rows</strong>";
		}
		else
		{
		   PRINT "<strong>Query FAILED. Sie haben m&ouml;glicherweise nicht die ben&ouml;tigten Rechte!</strong>";
		}
	}
}

$userdata = new editUserData();
$userdata->edit($firstname, $lastname, $address, $postcode, $city, $country, $phone, $employer, $mail, $title, $homepage, $position, $user_id);

PRINT "<br>";
PRINT "<a href=\"index.php\">Zur&uuml;ck</a>";
PRINT "</body>";
PRINT "</html>";

/* Close the database connection */
MYSQL_CLOSE();
?>